/*
 * @(#)WorkflowTrackParameterValue.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.DataSourceFactory;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
import com.dcivision.workflow.bean.WorkflowTrackParameterValue;

/**
 * WorkflowTrackParameterValueDAObject.java
 *
 * This class is the data access bean for table "WORKFLOW_TRACK_PARAMETER_VALUE".
 *
 * @author Angus Shiu
 * @company DCIVision Limited
 * @creation date 26/02/2004
 * @version $Revision: 1.10 $
 */

public class WorkflowTrackParameterValueDAObject extends AbstractDAObject {
  
  public static final String REVISION = "$Revision: 1.10 $";
  
  public static final String TABLE_NAME = "WORKFLOW_TRACK_PARAMETER_VALUE";
  
  public WorkflowTrackParameterValueDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }
  
  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("TRACK_ID");
    this.vecDBColumn.add("PROGRESS_ID");
    this.vecDBColumn.add("PARAMETER_NAME");
    this.vecDBColumn.add("PARAMETER_VALUE_1");
    this.vecDBColumn.add("PARAMETER_VALUE_2");
    this.vecDBColumn.add("PARAMETER_VALUE_3");
    this.vecDBColumn.add("PARAMETER_VALUE_4");
    this.vecDBColumn.add("PARAMETER_VALUE_5");
    this.vecDBColumn.add("PARAMETER_VALUE_6");
    this.vecDBColumn.add("PARAMETER_VALUE_7");
    this.vecDBColumn.add("PARAMETER_VALUE_8");
    this.vecDBColumn.add("PARAMETER_VALUE_9");
    this.vecDBColumn.add("PARAMETER_VALUE_10");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }
  
  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5, A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs, "PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs, "PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs, "PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs, "PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
          tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
          return(tmpWorkflowTrackParameterValue);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5,  A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        
        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }
        
        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());
        
        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }
        
        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
        
        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();
        
        this.positionCursor(rs, startOffset, pageSize);
        
        while (rs.next() && rowLoopCnt<pageSize) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs, "PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs, "PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs, "PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs, "PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
          tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
          tmpWorkflowTrackParameterValue.setRecordCount(totalNumOfRecord);
          tmpWorkflowTrackParameterValue.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpWorkflowTrackParameterValue);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }
  
  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5,  A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs, "PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs, "PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs, "PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs, "PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
          tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
          result.add(tmpWorkflowTrackParameterValue);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = (WorkflowTrackParameterValue)((WorkflowTrackParameterValue)obj).clone();
    
    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   WORKFLOW_TRACK_PARAMETER_VALUE(ID, TRACK_ID, PROGRESS_ID, PARAMETER_NAME, PARAMETER_VALUE_1, PARAMETER_VALUE_2, PARAMETER_VALUE_3, PARAMETER_VALUE_4, PARAMETER_VALUE_5, PARAMETER_VALUE_6, PARAMETER_VALUE_7, PARAMETER_VALUE_8, PARAMETER_VALUE_9, PARAMETER_VALUE_10, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpWorkflowTrackParameterValue.getTrackID());
        setPrepareStatement(preStat, 3, tmpWorkflowTrackParameterValue.getProgressID());
        setPrepareStatement(preStat, 4, tmpWorkflowTrackParameterValue.getParameterName());
        setPrepareStatement(preStat, 5, tmpWorkflowTrackParameterValue.getParameterValue1());
        setPrepareStatement(preStat, 6, tmpWorkflowTrackParameterValue.getParameterValue2());
        setPrepareStatement(preStat, 7, tmpWorkflowTrackParameterValue.getParameterValue3());
        setPrepareStatement(preStat, 8, tmpWorkflowTrackParameterValue.getParameterValue4());
        setPrepareStatement(preStat, 9, tmpWorkflowTrackParameterValue.getParameterValue5());
        setPrepareStatement(preStat, 10, tmpWorkflowTrackParameterValue.getParameterValue6());
        setPrepareStatement(preStat, 11, tmpWorkflowTrackParameterValue.getParameterValue7());
        setPrepareStatement(preStat, 12, tmpWorkflowTrackParameterValue.getParameterValue8());
        setPrepareStatement(preStat, 13, tmpWorkflowTrackParameterValue.getParameterValue9());
        setPrepareStatement(preStat, 14, tmpWorkflowTrackParameterValue.getParameterValue10());
        setPrepareStatement(preStat, 15, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 16, new Integer(0));
        if (tmpWorkflowTrackParameterValue.getCreate_id() != null) {
          setPrepareStatement(preStat, 17, tmpWorkflowTrackParameterValue.getCreate_id());
        } else {
          setPrepareStatement(preStat, 17, sessionContainer.getUserRecordID());
        }
        setPrepareStatement(preStat, 18, currTime);
        setPrepareStatement(preStat, 19, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 20, currTime);
        preStat.executeUpdate();
        tmpWorkflowTrackParameterValue.setID(nextID);
        tmpWorkflowTrackParameterValue.setCreatorID(sessionContainer.getUserRecordID());
        tmpWorkflowTrackParameterValue.setCreateDate(currTime);
        tmpWorkflowTrackParameterValue.setUpdaterID(sessionContainer.getUserRecordID());
        tmpWorkflowTrackParameterValue.setUpdateDate(currTime);
        tmpWorkflowTrackParameterValue.setUpdateCount(new Integer(0));
        if (!Utility.isEmpty(tmpWorkflowTrackParameterValue.getCreate_id())) {
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreate_id()));
        } else {
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
        }
        tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
        return(tmpWorkflowTrackParameterValue);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = (WorkflowTrackParameterValue)((WorkflowTrackParameterValue)obj).clone();
    
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE WORKFLOW_TRACK_PARAMETER_VALUE ");
        sqlStat.append("SET  TRACK_ID=?, PROGRESS_ID=?, PARAMETER_NAME=?, PARAMETER_VALUE_1=?, PARAMETER_VALUE_2=?, PARAMETER_VALUE_3=?, PARAMETER_VALUE_4=?, PARAMETER_VALUE_5=?, PARAMETER_VALUE_6=?, PARAMETER_VALUE_7=?, PARAMETER_VALUE_8=?, PARAMETER_VALUE_9=?, PARAMETER_VALUE_10=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpWorkflowTrackParameterValue.getTrackID());
        setPrepareStatement(preStat, 2, tmpWorkflowTrackParameterValue.getProgressID());
        setPrepareStatement(preStat, 3, tmpWorkflowTrackParameterValue.getParameterName());
        setPrepareStatement(preStat, 4, tmpWorkflowTrackParameterValue.getParameterValue1());
        setPrepareStatement(preStat, 5, tmpWorkflowTrackParameterValue.getParameterValue2());
        setPrepareStatement(preStat, 6, tmpWorkflowTrackParameterValue.getParameterValue3());
        setPrepareStatement(preStat, 7, tmpWorkflowTrackParameterValue.getParameterValue4());
        setPrepareStatement(preStat, 8, tmpWorkflowTrackParameterValue.getParameterValue5());
        setPrepareStatement(preStat, 9, tmpWorkflowTrackParameterValue.getParameterValue6());
        setPrepareStatement(preStat, 10, tmpWorkflowTrackParameterValue.getParameterValue7());
        setPrepareStatement(preStat, 11, tmpWorkflowTrackParameterValue.getParameterValue8());
        setPrepareStatement(preStat, 12, tmpWorkflowTrackParameterValue.getParameterValue9());
        setPrepareStatement(preStat, 13, tmpWorkflowTrackParameterValue.getParameterValue10());
        setPrepareStatement(preStat, 14, new Integer(tmpWorkflowTrackParameterValue.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 15, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 16, currTime);
        setPrepareStatement(preStat, 17, tmpWorkflowTrackParameterValue.getID());
        setPrepareStatement(preStat, 18, tmpWorkflowTrackParameterValue.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpWorkflowTrackParameterValue.setUpdaterID(sessionContainer.getUserRecordID());
          tmpWorkflowTrackParameterValue.setUpdateDate(currTime);
          tmpWorkflowTrackParameterValue.setUpdateCount(new Integer(tmpWorkflowTrackParameterValue.getUpdateCount().intValue() + 1));
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
          tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
          return(tmpWorkflowTrackParameterValue);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = (WorkflowTrackParameterValue)((WorkflowTrackParameterValue)obj).clone();
    
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpWorkflowTrackParameterValue.getID());
        setPrepareStatement(preStat, 2, tmpWorkflowTrackParameterValue.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpWorkflowTrackParameterValue);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = (WorkflowTrackParameterValue)this.oldValue;
    
    if (tmpWorkflowTrackParameterValue != null) {
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getTrackID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getProgressID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterName()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue1()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue2()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue3()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue4()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue5()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue6()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue7()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue8()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue9()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue10()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdateDate()));
    }
    
    tmpWorkflowTrackParameterValue = (WorkflowTrackParameterValue)obj;
    if (tmpWorkflowTrackParameterValue != null) {
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getID()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getTrackID()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getProgressID()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterName()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue1()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue2()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue3()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue4()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue5()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue6()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue7()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue8()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue9()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getParameterValue10()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpWorkflowTrackParameterValue.getUpdateDate()));
    }
    
    auditTrailBase(opMode, oldValues, newValues);
  }
  
  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  /**
   * Gets a list of track parameter value of the given workflow track
   * 
   * @param trackID The workflow track ID
   * @return List of parameter values
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowTrackParameterValue
   */
  public synchronized List getListByTrackID(Integer trackID) throws ApplicationException {
    return getListByTrackIDParameterName(trackID, null);
  }
  /**
   * Gets a list of track parameter value with the given parameter name 
   * of the given workflow track
   * 
   * @param trackID The workflow track ID
   * @param parameterName The parameter name
   * @return List of parameter values
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowTrackParameterValue
   */
  public synchronized List getListByTrackIDParameterName(Integer trackID, String parameterName) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5, A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.TRACK_ID = ? ");
        if (parameterName!=null) {
          sqlStat.append("AND A.PARAMETER_NAME = ? ");
        }
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, trackID);
        if (parameterName!=null) {
          this.setPrepareStatement(preStat, 3, parameterName);
        }
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs, "PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs, "PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs, "PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs, "PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowTrackParameterValue.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getCreatorID()));
          tmpWorkflowTrackParameterValue.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowTrackParameterValue.getUpdaterID()));
          result.add(tmpWorkflowTrackParameterValue);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Gets a list of track parameter value of the given owner within the given time period
   * 
   * @param ownerID The owner ID
   * @param startDate Time range start date
   * @param endDate Time range end date
   * @return List of parameter values
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowTrackParameterValue
   */
  public List getListByOwnerID(Integer ownerID,Timestamp startDate,Timestamp endDate)
  throws ApplicationException {
    SessionContainer sessionContainer = this.getSessionContainer();
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    int length = 0;
    int i = 0;
    
    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5, A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE A.RECORD_STATUS = ? AND A.CREATOR_ID = ? ");
        
        if ( (startDate != null) && (endDate != null)) {
          if (DataSourceFactory.getDatabaseType() == DataSourceFactory.DB_ORACLE) {
            sqlStat.append(" AND ((PARAMETER_VALUE_2 > to_date('" + startDate +
                "', 'YYYY-MM-DD HH24:MI:SS')  AND PARAMETER_VALUE_2 < to_date('" + endDate + "', 'YYYY-MM-DD HH24:MI:SS') ) OR (PARAMETER_VALUE_3 > to_date('" +
                startDate + "', 'YYYY-MM-DD HH24:MI:SS')  AND PARAMETER_VALUE_3 < to_date('" + endDate + "', 'YYYY-MM-DD HH24:MI:SS') ) OR");
            sqlStat.append(" (PARAMETER_VALUE_2 < to_date('" + startDate + "', 'YYYY-MM-DD HH24:MI:SS') AND PARAMETER_VALUE_3 > to_date('" +
                startDate + "', 'YYYY-MM-DD HH24:MI:SS') ) OR (PARAMETER_VALUE_2 < to_date('" + endDate +
                "', 'YYYY-MM-DD HH24:MI:SS') AND PARAMETER_VALUE_3 > to_date('" + endDate + "', 'YYYY-MM-DD HH24:MI:SS') ))");
          } else {
            sqlStat.append(" AND ((PARAMETER_VALUE_2 > '" + startDate +
                "' AND PARAMETER_VALUE_2 < '" + endDate + "') OR (PARAMETER_VALUE_3 > '" +
                startDate + "' AND PARAMETER_VALUE_3 < '" + endDate + "') OR");
            sqlStat.append(" (PARAMETER_VALUE_2 < '" + startDate + "' AND PARAMETER_VALUE_3 > '" +
                startDate + "') OR (PARAMETER_VALUE_2 < '" + endDate +
                "' AND PARAMETER_VALUE_3 > '" + endDate + "'))");
          }
        }
        
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, GlobalConstant.STATUS_ACTIVE);
        setPrepareStatement(preStat, 2, ownerID);
        rs = preStat.executeQuery();
        
        while (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs,"PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs,"PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs,"PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs,"PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs,"RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs,"CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs,"UPDATE_DATE"));
          result.add(tmpWorkflowTrackParameterValue);
        }
        return result;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }
  /**
   * Deletes all the parameter value with the specified name of the given workflow track
   * 
   * @param trackID The workflow track ID
   * @param parameterName The parameter naem
   * @throws ApplicationException
   */
  public synchronized void deleteByTrackIDParameterName(Integer trackID, String parameterName) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE ");
        sqlStat.append("WHERE  TRACK_ID=? AND PARAMETER_NAME=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, trackID);
        setPrepareStatement(preStat, 2, parameterName);
        updateCnt = preStat.executeUpdate();
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of parameter value of the given owner start from the given date
   * 
   * @param fromDate The start date
   * @param ownerID The owner ID
   * @return List of parameter values
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowTrackParameterValue
   */
  public synchronized List getByFromTime(String fromDate,Integer ownerID) throws ApplicationException{
    SessionContainer sessionContainer = this.getSessionContainer();
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    int length = 0;
    int i = 0;
    
    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5, A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE A.RECORD_STATUS = ? AND A.CREATOR_ID = ? ");
        sqlStat.append("AND ").append(this.getSearchColumn("PARAMETER_VALUE_2")).append(" LIKE ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, GlobalConstant.STATUS_ACTIVE);
        setPrepareStatement(preStat, 2, ownerID);
        setPrepareStatement(preStat, 3, this.getFormattedKeyword(fromDate, "LIKE"));
        
        rs = preStat.executeQuery();
        
        while (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs,"PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs,"PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs,"PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs,"PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs,"RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs,"CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs,"UPDATE_DATE"));
          result.add(tmpWorkflowTrackParameterValue);
        }
        return result;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
    
  }
  /**
   * Gets a list of parameter value of the given owner up to the given date
   * 
   * @param fromDate The end date
   * @param ownerID The owner ID
   * @return List of parameter values
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowTrackParameterValue
   */
  public synchronized List getByToTime(String fromDate,Integer ownerID) throws ApplicationException{
    SessionContainer sessionContainer = this.getSessionContainer();
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    int length = 0;
    int i = 0;
    
    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.TRACK_ID, A.PROGRESS_ID, A.PARAMETER_NAME, A.PARAMETER_VALUE_1, A.PARAMETER_VALUE_2, A.PARAMETER_VALUE_3, A.PARAMETER_VALUE_4, A.PARAMETER_VALUE_5, A.PARAMETER_VALUE_6, A.PARAMETER_VALUE_7, A.PARAMETER_VALUE_8, A.PARAMETER_VALUE_9, A.PARAMETER_VALUE_10, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_TRACK_PARAMETER_VALUE A ");
        sqlStat.append("WHERE A.RECORD_STATUS = ? AND A.CREATOR_ID = ? ");
        sqlStat.append("AND ").append(this.getSearchColumn("PARAMETER_VALUE_3")).append(" LIKE ? ");
        
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, GlobalConstant.STATUS_ACTIVE);
        setPrepareStatement(preStat, 2, ownerID);
        setPrepareStatement(preStat, 3, this.getFormattedKeyword(fromDate, "LIKE"));
        rs = preStat.executeQuery();
        
        while (rs.next()) {
          WorkflowTrackParameterValue tmpWorkflowTrackParameterValue = new WorkflowTrackParameterValue();
          tmpWorkflowTrackParameterValue.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowTrackParameterValue.setTrackID(getResultSetInteger(rs, "TRACK_ID"));
          tmpWorkflowTrackParameterValue.setProgressID(getResultSetInteger(rs, "PROGRESS_ID"));
          tmpWorkflowTrackParameterValue.setParameterName(getResultSetString(rs, "PARAMETER_NAME"));
          tmpWorkflowTrackParameterValue.setParameterValue1(getResultSetString(rs, "PARAMETER_VALUE_1"));
          tmpWorkflowTrackParameterValue.setParameterValue2(getResultSetString(rs,"PARAMETER_VALUE_2"));
          tmpWorkflowTrackParameterValue.setParameterValue3(getResultSetString(rs, "PARAMETER_VALUE_3"));
          tmpWorkflowTrackParameterValue.setParameterValue4(getResultSetString(rs,"PARAMETER_VALUE_4"));
          tmpWorkflowTrackParameterValue.setParameterValue5(getResultSetString(rs, "PARAMETER_VALUE_5"));
          tmpWorkflowTrackParameterValue.setParameterValue6(getResultSetString(rs, "PARAMETER_VALUE_6"));
          tmpWorkflowTrackParameterValue.setParameterValue7(getResultSetString(rs,"PARAMETER_VALUE_7"));
          tmpWorkflowTrackParameterValue.setParameterValue8(getResultSetString(rs, "PARAMETER_VALUE_8"));
          tmpWorkflowTrackParameterValue.setParameterValue9(getResultSetString(rs,"PARAMETER_VALUE_9"));
          tmpWorkflowTrackParameterValue.setParameterValue10(getResultSetString(rs, "PARAMETER_VALUE_10"));
          tmpWorkflowTrackParameterValue.setRecordStatus(getResultSetString(rs,"RECORD_STATUS"));
          tmpWorkflowTrackParameterValue.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowTrackParameterValue.setCreateDate(getResultSetTimestamp(rs,"CREATE_DATE"));
          tmpWorkflowTrackParameterValue.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowTrackParameterValue.setUpdateDate(getResultSetTimestamp(rs,"UPDATE_DATE"));
          result.add(tmpWorkflowTrackParameterValue);
        }
        return result;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
}
